<template>
    <div>
        <h1>病房新增</h1>
        <table class="table">
            <tr>
                <td>病房名称</td>
                <td><input type="text" v-model="data.rfh"></td>
            </tr>
            <tr>
                <td>所属科室</td>
                <td><select v-model="data.rid">
                    <option value="0">请选择</option>
                    <option v-for="x in xl" :value="x.rid">{{x.rname}}</option>
                </select></td>
            </tr>
            <tr>
                <td>床位总数量</td>
                <td><input type="text" v-model="data.roomcw"></td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" name="zt" value="1" v-model="data.roomState">维修
                    <input type="radio" name="zt" value="2" v-model="data.roomState">启用
                </td>
            </tr>
            <tr>
                <td>空闲床数量</td>
                <td><input type="text" v-model="data.roomkx"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="新增" @click="add"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import moment from 'moment'
const router=useRouter();
const route=useRoute();
const data=ref({
    "roomId": 0,
  "rfh": "",
  "rid": 0,
  "roomcw": 0,
  "roomState": 0,
  "roomkx": 0,
})
const add=()=>{
    if(data.value.rfh==""||data.value.rfh.length>6){
        alert("病房名称不能为空且不能超过6个字符")
        return
    }
    axios.post("/api/Roombf/AddRoombf",data.value).then(res=>{
        if(res.data>0){
            alert("新增成功")
            router.push({path:"/bshow"})
        }else{
            alert("新增失败")
            return
        }
    })
}
onMounted(() => {
  xlk()  
})
const xl=ref({})
const xlk=()=>{
    axios.get("/api/RoomKs/GetRoomKsBy").then(res=>{
        xl.value=res.data
    })
}
</script>

<style scoped>

</style>